<template>
  <div>
    <QueryFrame v-on:query="quickQuery" />
    <div class="tables">
      <el-table :data="noticeTable" style="margin-top: 24px">
        <el-table-column label="序号" width="55" align="center">
          <template slot-scope="scope">
            {{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}
          </template>
        </el-table-column>
        <el-table-column
          type="selection"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column prop="noticeTitle" label="名称" align="center"/>
        <el-table-column prop="noticeType" label="公告类型" align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType"/>
          </template>
        </el-table-column>
        <el-table-column
          prop="isRead"
          label="状态"
          align="center"
          :formatter="noticeRead"
        />
        <el-table-column prop="createBy" align="center" label="创建人">
          <template v-slot="{row}">{{labelNickName(row.createBy)}}</template>
        </el-table-column>
        <el-table-column prop="createTime" align="center" label="时间"/>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-link
              type="primary"
              class="opertion"
              :disabled="scope.row.isRead == '1'"
              @click="hadbeenRead(scope.row)"
              >已读</el-link
            >
            <el-link type="primary" @click="toDetail(scope.row)">详情</el-link>

            <!-- <el-link type="primary" @click="handleClick(scope.row)">删除</el-link> -->
          </template>
        </el-table-column>
      </el-table>

      <!-- <el-button type="primary" style=" width: 120px;height: 36px">管理员</el-button> -->
    </div>
    <pagination
      v-show="noticeTotal > 0"
      :total="noticeTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="localNoticeList"
    />
    <el-dialog title="公告详情" :visible.sync="noticeDetailVisible" append-to-body>
      <div v-loading="loading">
        <div style="max-height: 76vh; overflow-y: auto;" v-html="noticeForm.noticeContent || ''"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { noticeList, noticeReadDone, getNoticeDetail } from "@/api/basic/center";
import QueryFrame from "../QueryFrame/index";
import { nickName } from '@/mixins/nickName';

export default {
  props: {
    innerFormat: Function,
  },
  mixins: [nickName('noticeTable')],
  dicts: ['sys_notice_type'],
  data() {
    return {
      loading: false,
      noticeForm: {},
      noticeDetailVisible: false,
      // 公告数据总数
      noticeTotal: 0,
      //公告表
      noticeTable: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isRead: "",
        noticeTitle: "",
      },
    };
  },
  created() {
    this.localNoticeList();
  },
  methods: {
    quickQuery(data) {
      this.queryParams.noticeTitle = data;
      this.localNoticeList();
    },
    hadbeenRead(row) {
      let noticeId = row.noticeId;
      noticeReadDone({ noticeId }).then((res) => {
        if (res.code === 200) {
          this.localNoticeList();
        }
      });
    },
    toDetail(row) {
      this.loading = true
      this.noticeDetailVisible = true
      getNoticeDetail(row.noticeId).then(res => {
        this.noticeForm = res.data
        this.loading = false
      })
    },

    localNoticeList() {
      noticeList(this.queryParams).then((res) => {
        if (res.code === 200 && res.rows.length > 0) {
          this.noticeTable = res.rows;
          this.noticeTotal = res.total;
        } else {
          this.noticeTable = [];
        }
      });
    },

    // 公告数据转换
    noticeRead(row) {
      return this.innerFormat(row.isRead);
    },
  },
  components: {
    QueryFrame,
  },
};
</script>

<style>
</style>
